/*
    Dao FLTK2
    Copyright (C) 2010 Belousov Oleg <belousov.oleg@gmail.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <fltk/run.h>
#include <dao.h>

#include "widget.h"
#include "group.h"
#include "window.h"
#include "glwindow.h"
#include "button.h"
#include "drawbox.h"
#include "image.h"
#include "gl.h"

DAO_INIT_MODULE;

DaoVmSpace  *VmSpace;

static void fltk_run(DaoContext *ctx, DValue *p[], int N) {
    int res = fltk::run();
    DaoContext_PutInteger(ctx, (int) res);
};

static void fltk_wait(DaoContext *ctx, DValue *p[], int N) {
    int res = fltk::wait(p[0]->v.f);
    DaoContext_PutInteger(ctx, (int) res);
};

static DaoFuncItem fltkMeth[] = {
    { fltk_run, "run() => int" },
    { fltk_wait, "wait(time:float) => int" },
    { NULL, NULL }
};

DaoTypeBase guiTyper = {
    "fltk",
    NULL,
    NULL,       /* no constant number */
    fltkMeth,   /* methods */
    { NULL },   /* no parent type */
    { NULL },
    NULL,
    NULL        /* free by free() */
};

int DaoOnLoad(DaoVmSpace *vms, DaoNameSpace *ns) {
    DaoTypeBase *typers[] = {
        &guiTyper,
        &widgetTyper,
        &groupTyper,
        &windowTyper,
        &glwindowTyper,
        &buttonTyper,
        &drawboxTyper,
        &imageTyper,
        &glTyper,
        &gluTyper,
        NULL
    };

    DaoNameSpace_WrapTypes(ns, typers);
    VmSpace = vms;

    return 0;
};
